package com.example.androidmaps;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class Friends extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_friends);
		Database db = new Database(this);
		Friend f = new Friend();
		f.CloudId = 1;
		f.CloudUserId = 2;
		f.CloudUsername = "Bob";
		f.CurrentLocation = "There";
		f.Approved = true;
		db.InsertFriend(f);
		
		populateFriends();
		
		final Button button = (Button) findViewById(R.id.requestFriend);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	Intent intent = new Intent(Friends.this,Request_Friend.class);
            	Friends.this.startActivity(intent);
            }
        });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_friends, menu);
		return true;
	}
	
	public void populateFriends(){
		Database db = new Database(this);
		ListView lv = (ListView)findViewById(R.id.friendsList);
		ArrayList<Friend> fL = new ArrayList<Friend>();
		ArrayList<String> names = new ArrayList<String>();
		
		fL = db.GetAllFriends();
		
		for(int i = 0; i < fL.size(); i++){
			String name = fL.get(i).CloudUsername;
			names.add(name);
		}
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
				names);
		lv.setAdapter(adapter);
	}

}
